<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label="生产批号" prop="batchNumber">
        <el-input v-model="queryParams.batchNumber" placeholder="请输入生产批号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="采购方总部编码" prop="purchaserHqCode">
        <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="供应商编码" prop="supplierCode">
        <el-input v-model="queryParams.supplierCode" placeholder="请输入供应商编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="生产订单编号" prop="ipoNo">
        <el-input v-model="queryParams.ipoNo" placeholder="请输入生产订单编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="设备编号" prop="deviceNo">
        <el-input v-model="queryParams.deviceNo" placeholder="请输入设备编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="生产批次号" prop="productBatchNo">
        <el-input v-model="queryParams.productBatchNo" placeholder="请输入生产批次号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工序名称" prop="processName">
        <el-input v-model="queryParams.processName" placeholder="请输入工序名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="品类编码" prop="categoryCode">
        <el-input v-model="queryParams.categoryCode" placeholder="请输入品类编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="种类编码" prop="subclassCode">
        <el-input v-model="queryParams.subclassCode" placeholder="请输入种类编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工序编码" prop="processCode">
        <el-input v-model="queryParams.processCode" placeholder="请输入工序编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['develop:FactoryProductBaogong:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                   @click="handleUpdate" v-hasPermi="['develop:FactoryProductBaogong:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
          <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                     v-hasPermi="['develop:FactoryProductBaogong:remove']">删除</el-button>
        </el-popconfirm>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" v-hasPermi="['develop:FactoryProductBaogong:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="生产批号" align="center" prop="batchNumber"/>
      <el-table-column label="加工件数" align="center" prop="processCount"/>
      <el-table-column label="生产完成时间" align="center" prop="finishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购方总部编码" align="center" prop="purchaserHqCode"/>
      <el-table-column label="供应商编码" align="center" prop="supplierCode"/>
      <el-table-column label="生产订单编号" align="center" prop="ipoNo"/>
      <el-table-column label="设备编号" align="center" prop="deviceNo"/>
      <el-table-column label="生产批次号" align="center" prop="productBatchNo"/>
      <el-table-column label="工序名称" align="center" prop="processName"/>
      <el-table-column label="品类编码" align="center" prop="categoryCode"/>
      <el-table-column label="种类编码" align="center" prop="subclassCode"/>
      <el-table-column label="工序编码" align="center" prop="processCode"/>
      <el-table-column label="生产工艺路线编码" align="center" prop="processNo"/>
      <el-table-column label="生产车间编码" align="center" prop="workshopCode"/>
      <el-table-column label="生产车间名称" align="center" prop="workshopName"/>
      <el-table-column label="生产工单编号" align="center" prop="woNo"/>
      <el-table-column label="计划开始时间" align="center" prop="planStartTime"/>
      <el-table-column label="计划结束时间" align="center" prop="planEndTime"/>
      <el-table-column label="实际开始时间" align="center" prop="actualStartDate"/>
      <el-table-column label="实际结束时间" align="center" prop="actualFinishDate"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus"/>
      <el-table-column label="客户所属省份" align="center" prop="buyerProvince"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProductBaogong:edit']">修改</el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:FactoryProductBaogong:remove']">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <factoryProductBaogong-form ref="form" @ok="getList"></factoryProductBaogong-form>
  </div>
</template>

<script>
  import { deleteAction, getAction } from '@/api/manage'
  import FactoryProductBaogongForm from '@/views/develop/factory/factoryProductBaogong/module/FactoryProductBaogongForm'

  export default {
    name: "FactoryProductBaogongList",
    components: {
      FactoryProductBaogongForm,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 报工信息数据表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          projectId: null,
          orderId: null,
          goodsId: null,
          batchNumber: null,
          processMethod: null,
          processCount: null,
          finishTime: null,
          purchaserHqCode: null,
          supplierCode: null,
          ipoNo: null,
          insideNo: null,
          deviceNo: null,
          productBatchNo: null,
          processName: null,
          categoryCode: "60",
          subclassCode: "60004",
          processCode: null,
          processNo: null,
          workshopId: null,
          workshopCode: null,
          workshopName: null,
          woNo: null,
          productId: null,
          dataSource: null,
          dataSourceCreateTime: null,
          planStartTime: null,
          planEndTime: null,
          actualStartDate: null,
          actualFinishDate: null,
          orderStatus: null,
          buyerProvince: null,
          ownerId: null,
          openId: null,
          wavyStatus: null
        },
        url: {
          list:'/factoryProductBaogong/factoryProductBaogong/list',
          remove:'/factoryProductBaogong/factoryProductBaogong/',
          export:'/factoryProductBaogong/factoryProductBaogong/export',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed () {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      /** 查询报工信息数据列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight () {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        deleteAction(this.url.remove, ids).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `factoryProductBaogong_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
